const app = getApp()
import {
  HomeIndex
} from 'index-modal.js';
import {
  Config
} from '../../../utils/config.js';
var Function = require("../../../utils/function.js");
var index = new HomeIndex(); //实例化 首页 对象


Page({
  data: {
    evaarr: [{ 'name': '全部', type: 7 }, { 'name': '有图', type: 6 },
      { 'name': '超级满意', type: 5 }, { 'name': '满意', type: 4 }, { 'name': '不怎么样', type: 3 }
      , { 'name': '不满意', type: 2 }, { 'name': '很失望', type: 1 }],
    pagesize:1,
    type:7,
    activeindex:0,
    id:'',
    isbottom:true,
    type_ed:1,  //1是门店评价2为理疗师评价
    pinarr:[],
    url:Config.Url,
    noData:false,
    
  },
  
  onLoad: function (options) {
    this.setData({ id: options.id, type_ed: options.type})
    if (this.data.type_ed == 1){
      this._fulldiscuss()
    }else{
      this._doctordiscuss()
    }
  },
  //预览图片
  previewImage:function(e){
    let that=this;
    let index = Function.getDataSet(e,'index');
    let url = Function.getDataSet(e,'url');
    wx.previewImage({
      current: url, // 当前显示图片的http链接
      urls: that.data.pinarr[index].pic // 需要预览的图片http链接列表
    })
  },
  

  _fulldiscuss(){
    let that =this;
    let data ={
      page: that.data.pagesize,
      type:that.data.type,
      id: that.data.id
    };
    index.fulldiscuss(data,(res)=>{

       if(res.code == 200){
         if (res.data.length == 0 && that.data.pagesize==1){
          //  wx.showToast({
          //    title: '暂无数据',
          //    icon:'none',
          //    duration:1000,
          //  })
          //  return;
          that.setData({
            noData: true
          })
         }else{
           let pinarr = that.data.pinarr;
           for (let i = 0; i < res.data.length; i++) {
             if (res.data[i].pic){
               for (let j = 0; j < res.data[i].pic.length; j++) {
                 res.data[i].pic[j] = that.data.url + res.data[i].pic[j];
                 
               }
             }
             
           }
           let pinarr1 = pinarr.concat(res.data);
           that.setData({ pinarr: pinarr1, noData: false })
           res.data.length < 10 ? that.setData({ isbottom: false}) : that.setData({ isbottom: true})
         }
        
       }
    })
  },
  seleall(e){
    let type = e.currentTarget.dataset.type;
    let activeindex = e.currentTarget.dataset.index;
    if (activeindex == this.data.activeindex){
      return;
    }
    this.setData({
      activeindex, type, pagesize: 1, pinarr: [], isbottom:true,
      noData: false
    })
    this._fulldiscuss()
  },

  onReachBottom(){
    let that = this;
    wx.showLoading({ title: '正在加载', mask: true })
    setTimeout(() => {
      that.data.pagesize++;
      that._fulldiscuss();
      wx.hideLoading()
    }, 1000)
    // if (this.data.isbottom && this.data.type_ed == 1){
    //   this._fulldiscuss(this.data.pagesize+1)
    // } else if (this.data.isbottom && this.data.type_ed == 2){
    //   this._doctordiscuss(this.data.pagesize + 1)
    // }
  },

  _doctordiscuss(){
    let that =this;
    let data ={
      id:that.data.id,
      page:that.data.pagesize
    }
    index.doctordiscuss(data,(res)=>{
      if (res.code == 200) {
        if (res.data.evaluate.length == 0) {
          wx.showToast({
            title: '暂无数据',
            icon: 'none',
            duration: 1000,
          })
          return;
        }
        let pinarr = that.data.pinarr;
        
        let pinarr1 = pinarr.concat(res.data.evaluate);
        that.setData({ pinarr: pinarr1 })
        res.data.length < 10 ? that.setData({ isbottom: false }) : that.setData({ isbottom: true })
      }
    })
  }


})
